<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use backend\helpers\ActionButton;
use dosamigos\ckeditor\CKEditor;
use backend\widgets\Translit\TranslitWidget;
use backend\models\Event;

/* @var $this yii\web\View */
/* @var $model backend\models\Event */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="create-form event-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'id_info_chanel')->dropdownList(
            \backend\models\InfoChanel::find()->select(['title', 'id'])->indexBy('id')->column(),
            [
                'prompt' => 'Выберете канал информации...'
            ]
        );
    ?>

    <?= $form->field($model, 'id_organization_branch')->dropdownList(
            \backend\models\OrganizationBranch::find()->select(['title', 'id'])->indexBy('id')->column(),
            [
                'prompt' => 'Выберете филиал...'
            ]
        );
    ?>

    <?= $form->field($model, 'id_type')->dropDownList(
            $types,
            [
                'prompt' => 'Выбор типа события',
            ]
        )->label('Тип') 
    ?>

    <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'alias')->widget(TranslitWidget::className(), [
            'clientOptions' => [
                'source' => 'event-title',
                'isNewRecord' => $model->isNewRecord,
            ],
        ])
    ?>

    <?= $form->field($model, 'description')->textarea(['rows' => 6]) ?>

    <?= $form->field($model, 'content')->widget(CKEditor::className(), [
            'options' => ['rows' => 6],
            'preset' => 'custom',
            'clientOptions' =>  [
                'toolbarGroups' => [
                    ['name' => 'clipboard', 'groups' => ['mode', 'undo', 'doctools']],
                    ['name' => 'editing', 'groups' => ['tools']],
                    ['name' => 'paragraph', 'groups' => ['templates', 'list', 'indent', 'align']],
                    ['name' => 'basicstyles', 'groups' => ['basicstyles', 'cleanup']],
                    ['name' => 'links'],
                    ['name' => 'others'],
                ]
            ]
        ]) 
    ?>
    
    <hr>
    <h2 class="sub-title">Изображения</h2>

    <?= $form->field($model, 'imageForCover')->fileInput(['accept' => 'image/*']) ?>
    
    <?php 
        if(!empty($model->prev_img))
        {
            echo Html::img(
                'https://storage.yandexcloud.net/' .  Event::BUCKET_NAME  . '/'. $model->prev_img, 
                $options = ['class' => 'img-thumbnail', 'style' => ['width' => '280px']]
            );
        }
    ?>

   <hr>

    <?= $form->field($model, 'imagesForGallery[]')->fileInput(['multiple' => true, 'accept' => 'image/*']) ?>

    <?php 
        if(!empty($model->gallery_img))
        {
            foreach(explode(',', $model->gallery_img) as $image)
            {
                echo '<div class="img-thumbnail">';
                echo Html::img(
                    'https://storage.yandexcloud.net/' . Event::BUCKET_NAME . '/' . $image, 
                    $options = ['class' => 'img-thumbnail', 'style' => ['width' => '260px', 'display' => 'block']]
                );
                ActionButton::deleteImage($model->id, $image, 'Вы точно хотите удалить изображение?', 'deleteEvent');
                echo '</div>';
            }   
        }
    ?>

    <hr>
    <h2 class="sub-title">Расписание</h2>

    <div class="row">
        <?= $form->field($model, 'date_start', ['options' => ['class' => 'col-sm-4']])->input('date') ?>

        <?= $form->field($model, 'date_end', ['options' => ['class' => 'col-sm-4']])->input('date') ?>

        <?= $form->field($model, 'time_start', ['options' => ['class' => 'col-sm-4']])->input('time') ?>
    </div>

    <?= $form->field($model, 'schedule_str')->textInput(['maxlength' => true]) ?>

    <hr>
    <h2 class="sub-title">Стоимость и покупка билетов</h2>

    <?= $form->field($model, 'id_price')->dropDownList(
            $prices,
            [
                'prompt' => 'Выбор ценовой категории',
            ]
        )->label('Цена') 
    ?>

    <div class="row">
        <?= $form->field($model, 'kassir_bo_type', ['options' => ['class' => 'col-sm-4']])->dropdownList(
                [
                    Event::KASSIR_TYPE_A => 'Тип А',
                ],
                [
                    'prompt' => 'Выберете тип...'
                ])
        ?>
        <?= $form->field($model, 'kassir_bo_id', ['options' => ['class' => 'col-sm-4']])->textInput() ?>
    </div>

    <?= $form->field($model, 'is_pushkart')->checkbox() ?> 
    <?= $form->field($model, 'is_free')->checkbox() ?> 
    
    <hr>
    <h2 class="sub-title">Дополнительная информация</h2>

    <?= $form->field($model, 'rars_info')->dropdownList(
            [
                Event::RARS_0 => '0+',
                Event::RARS_6 => '6+',
                Event::RARS_12 => '12+',
                Event::RARS_16 => '16+',
                Event::RARS_18 => '18+',
            ],
            [
                'prompt' => 'Выберете классификацию...'
            ])
    ?>

    <?= $form->field($model, 'is_main_event')->checkbox() ?> 

    <hr>
    <div class="form-group">
        <?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
